package com.origin.baselibrary.utils

import android.app.Activity
import android.app.Application
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
import androidx.activity.ComponentActivity
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.FileProvider
import com.origin.utils.permissions.PermissionsUtils
import java.io.File

object AppFileUtils {




    /**
     * 安装apk
     */
    fun installApk(newApkFile: File, activity: Application) {
        val intent = Intent(Intent.ACTION_VIEW)
        intent.addCategory(Intent.CATEGORY_DEFAULT)
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
        val type = "application/vnd.android.package-archive"
        val uri: Uri
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

            uri = FileProvider.getUriForFile(
                activity,
                activity.packageName + ".fileprovider",
                newApkFile
            )
            intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
        } else {
            uri = Uri.fromFile(newApkFile)
        }
        intent.setDataAndType(uri, type)
        activity.startActivity(intent)
    }
}